﻿package plugin.juezhan.controller
{
    import com.sh.game.util.*;
    import morn.core.components.*;
    import morn.core.handlers.*;
    import plugin.juezhan.ui.*;
    import pluginfw.*;
    import view.light.*;

    public class TianGuanRankControl extends Object
    {
        private var mUI:JueZhanUIControl;
        private var mRankInfo:Object;
        private const FIRST_REWARD_ID:int = 207592;
        private const SECOND_REWARD_ID:int = 207593;

        public function TianGuanRankControl(param1:Object)
        {
            this.mUI = param1 as JueZhanUIControl;
            return;
        }// end function

        public function rankInit(param1:Object) : void
        {
            var _loc_4:int = 0;
            var _loc_6:Object = null;
            this.mRankInfo = param1;
            var _loc_2:* = param1[0].source;
            if (_loc_2.length > 0)
            {
                _loc_6 = _loc_2[0];
                this.ui.label_play.text = _loc_6[1];
                this.ui.label_zhiye.text = UIGlobel.getCareer(_loc_6[5]);
                this.ui.label_time.text = param1[1];
            }
            else
            {
                this.ui.label_play.text = "暂无";
                this.ui.label_zhiye.text = "暂无";
                this.ui.label_time.text = "暂无";
            }
            this.ui.imgTGFirst.visible = false;
            this.ui.rankList.array = _loc_2;
            this.ui.rankList.renderHandler = new Handler(this.rankRenderHandler);
            var _loc_3:Boolean = false;
            for each (_loc_4 in param1[1])
            {
                
                if (_loc_4 == UserData.getUserData("rid"))
                {
                    _loc_3 = true;
                    break;
                }
            }
            if (this.mRankInfo[2] > 0)
            {
                this.ui.rankrew.rnum.text = this.mRankInfo[2];
            }
            else
            {
                this.ui.rankrew.rnum.text = "暂无名次";
            }
            var _loc_5:* = this.mRankInfo[3] == 0;
            this.ui.rankrew.lingquBtn.disabled = true;
            if (_loc_5)
            {
                LightFactory.showlight(this.ui.rankLinkBtn);
                LightFactory.showlight(this.ui.lqlabel);
                this.ui.rankrew.lingquBtn.disabled = false;
            }
            (this.ui.rankrew as RankRewardCtrl).showreward(this.mRankInfo[2]);
            this.ui.rankrew.parent.setChildIndex(this.ui.rankrew, (this.ui.rankrew.parent.numChildren - 1));
            return;
        }// end function

        public function getRankReward() : void
        {
            LightFactory.clearlight(this.ui.rankLinkBtn);
            LightFactory.clearlight(this.ui.lqlabel);
            this.ui.rankrew.lingquBtn.disabled = true;
            return;
        }// end function

        private function rankRenderHandler(param1:Component, param2:int) : void
        {
            if (param2 >= this.ui.rankList.array.length)
            {
                return;
            }
            var _loc_3:* = param1.getChildByName("txtName") as Label;
            _loc_3.text = param1.dataSource[1];
            var _loc_4:* = param1.getChildByName("txtFloor") as Label;
            (param1.getChildByName("txtFloor") as Label).text = StringUtil.substitute("{0}重{1}层", param1.dataSource[4], param1.dataSource[2]);
            var _loc_5:* = param1.getChildByName("txtTime") as Label;
            (param1.getChildByName("txtTime") as Label).text = TimeDataFormatUtil.getLeftTimeStr(param1.dataSource[3]);
            var _loc_6:* = param1.getChildByName("label_zhiye") as Label;
            (param1.getChildByName("label_zhiye") as Label).text = UIGlobel.getCareer(param1.dataSource[5]);
            return;
        }// end function

        private function get ui() : JueZhanUIControl
        {
            return this.mUI;
        }// end function

    }
}
